/**
 * Copyright (C) 2015-2016 Guangzhou Xunhong Network Technology Co., Ltd. All rights reserved.
 * <p>
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * http://www.apache.org/licenses/LICENSE-2.0
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */

package com.jxccp.ui.view.adapter;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.bumptech.glide.load.engine.DiskCacheStrategy;
import com.bumptech.glide.request.RequestOptions;
import com.jxccp.ui.R;
import com.jxccp.ui.entities.JXOrderInfo;

import java.io.File;
import java.util.ArrayList;
import java.util.List;

public class JXOrderListAdapter extends JXBasicAdapter<JXOrderInfo, ListView> {

    private LayoutInflater mInflater;

    public JXOrderListAdapter(Context context, List<JXOrderInfo> list) {
        super(context, list);
        mInflater = (LayoutInflater) context.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        if (convertView == null) {
            convertView = mInflater.inflate(R.layout.jx_order_item, null);
        }
        JXOrderInfo orderInfo = list.get(position);
        ImageView orderImg = (ImageView) convertView.findViewById(R.id.iv_order);
        TextView orderIdView = (TextView) convertView.findViewById(R.id.tv_order_id);
        TextView orderDateView = (TextView) convertView.findViewById(R.id.tv_order_date);
        TextView orderstatusView = (TextView) convertView.findViewById(R.id.tv_order_status);

        orderIdView.setText("订单号："+orderInfo.getOrderId());
        Glide.with(context)
                .load(orderInfo.getStoreLogoUrl())
                .apply(new RequestOptions().placeholder(R.drawable.jx_ic_photo_default).fitCenter())
                .into(orderImg);
        orderDateView.setText("订单日期："+orderInfo.getOrderCreatTime());
        orderstatusView.setText("价格："+orderInfo.getOrderPayPrice());
        return convertView;
    }

    public void refresh(List<JXOrderInfo> orderList) {
        this.list.clear();
        this.list.addAll(orderList);
        notifyDataSetChanged();
    }

}
